In [1]:
'''
Read data from a file that looks like this:

2013-03-26 08:51:18     69.35   20.75
2013-03-26 08:56:19     69.35   20.75
2013-03-26 09:01:19     69.125  20.625
2013-03-26 09:06:20     69.6866 20.937
'''


Out[1]:
'\nRead data from a file that looks like this:\n\n2013-03-26 08:51:18     69.35   20.75\n2013-03-26 08:56:19     69.35   20.75\n2013-03-26 09:01:19     69.125  20.625\n2013-03-26 09:06:20     69.6866 20.937\n'

Method 1: use Pandas


In [2]:
import pandas as pd
log_file = './data/temperaturedata2013-03-25-22-19-23.log'
df = pd.read_csv(log_file, parse_dates =[[0,1]],header=None,index_col=0,
    sep=r"\s*",names=['date','time','F','C'])
df.plot();ylabel('temp')


Out[2]:
<matplotlib.text.Text at 0x319af90>

In [7]:
df_15 = df.resample('15min',how='mean')
df_15.plot();ylabel('temp')


Out[7]:
<matplotlib.text.Text at 0x3963790>

In [4]:
df.head(10)


Out[4]:
F C
date_time
2013-03-26 08:51:18 69.3500 20.750
2013-03-26 08:56:19 69.3500 20.750
2013-03-26 09:01:19 69.1250 20.625
2013-03-26 09:06:20 69.6866 20.937
2013-03-26 09:11:21 69.3500 20.750
2013-03-26 09:16:21 69.2366 20.687
2013-03-26 09:21:22 69.2366 20.687
2013-03-26 09:26:22 69.4616 20.812
2013-03-26 09:31:23 69.4616 20.812
2013-03-26 09:36:24 69.5750 20.875

In [ ]:

Method 2: Use numpy + Matplotlib


In [3]:
import numpy as np
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

In [17]:
data=np.genfromtxt(log_file,dtype=None,names=['date','time','F','C'])

In [20]:
dates=mdates.datestr2num(data['date']) # get the integer day
times,null=np.modf(mdates.datestr2num(data['time']))  # get fractional day

In [22]:
jd=dates+times # add fractional day to integer day

In [38]:
fig=plt.figure(figsize=(10,5)) 
ax1 = fig.add_subplot(111)
ax1.plot_date(jd,data['C'],'ko-');
plt.grid()
plt.ylabel('Temp')


Out[38]:
<matplotlib.text.Text at 0x4275090>

In [ ]: